﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;

namespace Protobuf_Gui.Domain
{
    [Serializable]
    [ContainType(typeof (PbImport), "Import")]
    [ContainType(typeof (PbMessage), "Message")]
    [ContainType(typeof (PbService), "Service")]
    public class PbFile : ProtocolElement
    {
        public PbFile(string name) : base(name)
        {
            Imports = new List<PbImport>();
            Messages = new List<PbMessage>();
            Services = new List<PbService>();
        }

        public List<PbImport> Imports { get; set; }

        public List<PbMessage> Messages { get; set; }

        public List<PbService> Services { get; set; }

        public override TreeNode ToTreeNode(TreeNode root)
        {
            throw new NotImplementedException();
        }

        public override void ToFile(TextWriter writer, uint nesting)
        {
            foreach (var import in Imports)
            {
                writer.WriteLine(import);
            }

            foreach (var message in Messages)
            {
                message.ToFile(writer, nesting + 1);
            }

            foreach (var service in Services)
            {
                service.ToFile(writer, nesting + 1);
            }
        }
    }
}